|
Branch predication is a strategy in computer architecture design for mitigating the costs usually associated with conditional branches, particularly branches to short sections of code. It does this by allowing each instruction to conditionally either perform an operation or do nothing. ==Overview== Most computer programs contain code which will be executed only under specific conditions depending on factors which cannot be determined before-hand, for example user input. As the majority of processors simply execute the next instruction in a sequence, the traditional solution is to insert ''branch'' instructions that allow a program to conditionally branch to a different section of code, thus changing the next step in the sequence. This was sufficient until designers began improving performance by implementing instruction pipelining, a method which is slowed down by branches. For a more thorough description of the problems which arose, and a popular solution, see branch predictor. Luckily, one of the more common patterns of code that normally relies on branching has a more elegant solution. Consider the following pseudocode:〔 if ''condition'' ''do this'' else ''do that'' On a system that uses conditional branching, this might translate to machine instructions looking similar to:〔 branch if ''condition'' to label 1 ''do that'' branch to label 2 label 1: ''do this'' label 2: ... With branch predication, all possible branch paths are coded inline, but some instructions execute while others do not. The basic idea is that each instruction is associated with a predicate (the word here used similarly to its usage in predicate logic) and that the instruction will only be executed if the predicate is true. The machine code for the above example using branch predication might look something like this:〔 (''condition'') do this (not ''condition'') do that Note that beside eliminating branches, less code is needed in total, provided the architecture provides predicated instructions. While this does not guarantee faster execution in general, it will if the do this and do that blocks of code are short enough. Typically, in order to claim a system has branch predication, most or all of the instructions must have this ability to execute conditionally based on a predicate. 抄文引用元・出典: フリー百科事典『 ウィキペディア(Wikipedia)』 ■ウィキペディアで「branch predication」の詳細全文を読む スポンサード リンク
|